package com.mdd.common.entity.zdjd.dto;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

@Data
@ApiModel("设备状态比例DTO")
public class DeviceStatusDTO implements Serializable {

    @ApiModelProperty(value = "设备状态名称")
    private String statusName;

    @ApiModelProperty(value = "设备数量")
    private Integer deviceAmount;

    @ApiModelProperty(value = "设备比例")
    private Double percentage;

    public static List<DeviceStatusDTO> convert(Map<Integer, Integer> map, Integer totalAmount) {
        ArrayList<DeviceStatusDTO> list = new ArrayList<>();
        if(!map.isEmpty()){
            map.forEach((status, amount) -> {
                DeviceStatusDTO deviceStatusDTO = new DeviceStatusDTO();
                if(status!=null && status==1){
                    deviceStatusDTO.setStatusName("在线设备数");
                } else if (status!=null && status==2) {
                    deviceStatusDTO.setStatusName("运行设备数");
                } else if (status==3) {
                    deviceStatusDTO.setStatusName("离线设备数");
                } else if (status==4) {
                    deviceStatusDTO.setStatusName("故障设备数");
                } else if (status==5) {
                    deviceStatusDTO.setStatusName("待维修设备数量");
                }
                deviceStatusDTO.setDeviceAmount(amount);
                if(totalAmount<=0){
                    deviceStatusDTO.setPercentage(0.0);
                }else{
                    BigDecimal bigDecimal = new BigDecimal(amount / totalAmount).setScale(6, BigDecimal.ROUND_HALF_UP);
                    deviceStatusDTO.setPercentage(bigDecimal.doubleValue());
                }
                list.add(deviceStatusDTO);
            });
        }
        return list;
    }

}
